<?php


namespace app\controller;


use app\model\Result;
use think\facade\Request;

class ImgController
{
    /**
     * 图片上传
     */
    public function imgUpload()
    {
        $img = request()->file('img');
        $param['type'] = Request::param('type');
        if(!$img){
            return json(Result::index(100,'图片文件接收报错！',$param));
        }

        $no = rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9);

        $info = $img->move("static/img/".$param['type'], $no.'-'.time().'.jpg');
        if(!$info){
            return '图片文件存储报错！';
        }
        $param['img'] = "static/img/".$param['type']."/".$no.'-'.time().'.jpg';

        return json(Result::index(200,'上传成功',$param));
    }
}
